package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.QrtzJobDetails;
import io.mybatis.example.springboot.service.QrtzJobDetailsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * QRTZ_JOB_DETAILS - 任务详细信息表
 *
 * @author mkj
 */
@RestController
@RequestMapping("qrtzJobDetailses")
public class QrtzJobDetailsController {

  @Autowired
  private QrtzJobDetailsService qrtzJobDetailsService;

  @PostMapping
  public DataResponse<QrtzJobDetailsDO> save(@RequestBody QrtzJobDetailsDO qrtzJobDetails) {
    return DataResponse.ok(qrtzJobDetailsService.save( qrtzJobDetails));
  }

  @GetMapping
  public RowsResponse<QrtzJobDetailsDO> findList(@RequestBody QrtzJobDetailsDO qrtzJobDetails) {
    return RowsResponse.ok(qrtzJobDetailsService.findList( qrtzJobDetails));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<QrtzJobDetailsDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzJobDetailsService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<QrtzJobDetailsDO> update(@PathVariable("id") Long id, @RequestBody QrtzJobDetailsDO qrtzJobDetails) {
    qrtzJobDetails.setId(id);
    return DataResponse.ok(qrtzJobDetailsService.update( qrtzJobDetails));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzJobDetailsService.deleteById(id) == 1);
  }

}
